package com.pisolution.scheduler.runtime.context;

import com.pisolution.scheduler.core.utils.JsonUtils;
import com.pisolution.scheduler.remote.command.Command;
import com.pisolution.scheduler.remote.command.CommandConverter;

import java.io.Serializable;
import java.util.Date;

/**
 * 任务执行的上下文环境.
 *
 * @author sora
 * @version 0.1.0
 */
public final class TaskExecutionContext implements Serializable, CommandConverter {
    private static final long serialVersionUID = 572709020908056421L;

    // -------------------------------------------------------------------------------------------------
    //  数据单元 (基础属性)
    // -------------------------------------------------------------------------------------------------

    /** 任务节点标识. */
    private int id;

    /** 任务节点名称. */
    private String name;

    /** 任务节点适配器类型. */
    private String type;

    /** 任务节点完整定义内容. */
    private String content;

    // -------------------------------------------------------------------------------------------------
    //  数据单元 (关联信息)
    // -------------------------------------------------------------------------------------------------

    /** 所属项目标识. */
    private int projectId;

    /** 所属工作流标识. */
    private int workflowId;

    /** 所属工作流实例标识. */
    private int workflowInstanceId;

    /** 执行任务实例的用户标识. */
    private int userId;

    // -------------------------------------------------------------------------------------------------
    //  数据单元 (执行环境)
    // -------------------------------------------------------------------------------------------------

    /** 负责运行该任务节点的工作节点主机地址. */
    private String host;

    /** 运行该任务节点的工作节点所在分组. */
    private String workerGroup;

    /** 运行任务节点的基础路径. */
    private String executePath;

    /** 任务节点运行日志的存储路径. */
    private String logPath;

    // -------------------------------------------------------------------------------------------------
    //  数据单元 (运行信息)
    // -------------------------------------------------------------------------------------------------

    /** 工作流实例调度时间. */
    private Date scheduleTime;

    /** 任务节点开始执行时间. */
    private Date startTime;

    // -------------------------------------------------------------------------------------------------
    //  指令转换
    // -------------------------------------------------------------------------------------------------

    @Override
    public Command convert() {
        final TaskExecuteCommand command = new TaskExecuteCommand();

        command.setContext(JsonUtils.serializeToString(this));
        return command.convert();
    }

    // -------------------------------------------------------------------------------------------------
    //  属性访问
    // -------------------------------------------------------------------------------------------------

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getProjectId() {
        return this.projectId;
    }

    public void setProjectId(int projectId) {
        this.projectId = projectId;
    }

    public int getWorkflowId() {
        return this.workflowId;
    }

    public void setWorkflowId(int workflowId) {
        this.workflowId = workflowId;
    }

    public int getWorkflowInstanceId() {
        return this.workflowInstanceId;
    }

    public void setWorkflowInstanceId(int workflowInstanceId) {
        this.workflowInstanceId = workflowInstanceId;
    }

    public int getUserId() {
        return this.userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getHost() {
        return this.host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getWorkerGroup() {
        return this.workerGroup;
    }

    public void setWorkerGroup(String workerGroup) {
        this.workerGroup = workerGroup;
    }

    public String getExecutePath() {
        return this.executePath;
    }

    public void setExecutePath(String executePath) {
        this.executePath = executePath;
    }

    public String getLogPath() {
        return this.logPath;
    }

    public void setLogPath(String logPath) {
        this.logPath = logPath;
    }

    public void setScheduleTime(Date scheduleTime) {
        this.scheduleTime = scheduleTime;
    }

    public Date getStartTime() {
        return this.startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }
}
